<?php
header("content-type:text/html;charset=utf-8;");
if (isset($_POST) && !empty($_POST)) {
    extract($_POST);
    $username = isset($username)?$username:'';
    $age = isset($age)?$age:'0';
    $address = isset($address)?$address:'';
    require './RunDbPdo.php';
    $model = new RunDbPdo();
    $model->configFile = './dbconfig/user.config.php';
    $insert_sql = "INSERT INTO mm_users (username,age,address) VALUES('{$username}','{$age}','{$address}')";
    $dasta = $model->query($insert_sql);
    $lastId = $model->getLastInsertId();
    $model->close();
    if ($lastId > 0) {
        $slice = $lastId % 2;
        $model->configFile = "./dbconfig/user{$slice}.config.php";
        $insert_sql = "INSERT INTO mm_users{$slice} (user_id,username,age,address) VALUES('{$lastId}','{$username}','{$age}','{$address}')";
        $dasta = $model->query($insert_sql);
        if($dasta==true){
            header('location:select.php?user_id='.$lastId);die;
        }
    }
    
    
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta charset="utf-8">
    <title>用户管理系统</title>
    <link href="./css/property-system.css" rel="stylesheet">
    <link href="./css/operate-system.css" rel="stylesheet">
        </head>
        <body>
            <main>
                <section class="content">
                    <fieldset class="form-list-32">
                        <h3 class="operate-title-1"><i></i>添加用户信息</h3>
                        <form action="add.php" id="editFormId" method="post" autocomplete="off">
                            <ul>
                                <li><h6>用户名：</h6><aside><input type="text" name="username" class="tbox30 tbox30-6"/></aside></li>
                                <li><h6>年龄：</h6><aside><input name="age" maxlength="11" class="tbox30 tbox30-6" type="text"></aside></li>
                                <li><h6>地址：</h6><aside><input name="address" class="tbox30 tbox30-6" type="text" ></aside></li>
                                <li class="agent-subbtn-wrap mt30px">
                                    <h6>&nbsp;</h6><aside><input class="btn-2" type="submit" value="提交"></aside>
                                </li>
                            </ul>

                        </form>
                    </fieldset>
                </section>
            </main>
    </body>
</html>

